import java.util.HashMap;

public class work1 {
    public String minWindow(String s, String t) {
        HashMap<Character,Integer>map=new HashMap<>();
        int slen=s.length();
        int tlen=t.length();
        if(slen<tlen)return"";
        if(s.equals(t))return t;
        for (int i = 0; i <tlen ; i++) {
            map.put(t.charAt(i),map.getOrDefault(t.charAt(i),0)+1);
        }
        HashMap<Character,Integer> map1=new HashMap<>();
        int left=0,right=0,count=0;
        int sret=Integer.MAX_VALUE;
        int begin=-1;
        while (right<slen){
            char temp=s.charAt(right);
            map1.put(temp,map1.getOrDefault(temp,0)+1);
            if(map1.get(temp).equals(map.getOrDefault(temp,0)))count++;
            while (count==map.size()&&left<=right){
                if(right-left+1<sret){
                    sret=right-left+1;
                    begin=left;
                }
                if(map1.get(s.charAt(left)).equals(map.getOrDefault(s.charAt(left),0)))count--;
                map1.put(s.charAt(left),map1.getOrDefault(s.charAt(left),0)-1);
                left++;
            }
            right++;
        }
        if(begin==-1)return "";
        else return s.substring(begin,begin+sret);
    }

}
